<template>
    <div class="export-data">
        <div class="export-data-title">
            <span>数据导出</span>
        </div>
        <div class="export-data-contents">
            <!--<div>-->
                <!--<div class="export-data-contents-title">1、导出订单详情</div>-->

                <!--<div style="">-->
                    <!--<div>-->
                        <!--<span style="margin-right: 10px">用户名称:</span>-->
                        <!--&lt;!&ndash;<el-input type="text" v-model="userName" style="width: 300px;"></el-input>&ndash;&gt;-->
                        <!--<el-select-->
                                <!--v-model="userName"-->
                               <!--filterable-->
                               <!--placeholder="请选择"-->
                                <!--:loading="loading"-->
                                <!--remote-->
                                <!--reserve-keyword-->
                                <!--:remote-method="remoteMethod"-->
                                <!--style="width: 300px;">-->
                            <!--<el-option-->
                                    <!--v-for="item in userOption"-->
                                    <!--:key="item.id"-->
                                    <!--:label="item.name +' '+ item.phone"-->
                                    <!--:value="item.id">-->
                            <!--</el-option>-->
                        <!--</el-select>-->
                    <!--</div>-->
                    <!--<div style="margin: 20px 0;">-->
                        <!--<span style="margin-right: 10px">单类选择:</span>-->
                        <!--<el-radio-group v-model="checkStatus" style="">-->
                            <!--<el-radio label="">全部</el-radio>-->
                            <!--<el-radio label="single">单件单</el-radio>-->
                            <!--<el-radio label="children">子单</el-radio>-->
                            <!--<el-radio label="parent">母单</el-radio>-->
                        <!--</el-radio-group>-->
                    <!--</div>-->
                    <!--<div>-->
                        <!--<span style="margin-right: 10px">状态选择:</span>-->
                        <!--<el-select v-model="orderStatus" multiple filterable placeholder="请选择" style="width: 300px;">-->
                            <!--<el-option-->
                                    <!--v-for="item in options"-->
                                    <!--:key="item.value"-->
                                    <!--:label="item.label"-->
                                    <!--:value="item.value">-->
                            <!--</el-option>-->
                        <!--</el-select>-->
                    <!--</div>-->
                    <!--<div style="display: flex;line-height: 42px;margin: 20px 0">-->
                        <!--<span>派送时间选择：</span><lar-field-date v-model="dateTimeOne"  :action="'search'" style="width: 300px;"></lar-field-date>-->
                    <!--</div>-->

                    <!--<el-button type="primary" :disabled="disabledOne" icon="el-icon-download" :loading="disabledOne" @click="exportOrderDetail">{{disabledOne?'导出中':'导出订单详情'}}</el-button>-->
                <!--</div>-->
            <!--</div>-->
            <div>
                <div class="export-data-contents-title">1、导出区域统计</div>
                <div >
                    <div style="display: flex;line-height: 42px;margin: 20px 0">
                        <span>派送时间选择：</span><lar-field-date v-model="dateTimeTwo" :action="'search'" style="width: 300px;"></lar-field-date>
                    </div>
                    <el-button type="primary"  :disabled="disabledTwo" icon="el-icon-download" :loading="disabledTwo"  @click="exportAreaStatics">{{disabledTwo?'导出中':'导出区域统计'}}</el-button>
                </div>
            </div>
            <div>
                <div class="export-data-contents-title">2、导出订单统计</div>

                <div style="display: flex;">
                    <el-button type="primary"  :disabled="disabledThree" icon="el-icon-download" :loading="disabledThree" @click="exportOrderStatics">{{disabledThree?'导出中':'导出订单统计'}}</el-button>
                </div>
            </div>
            <div>
                <div class="export-data-contents-title">3、导出司机</div>
                <div >
                    <div style="display: flex;line-height: 42px;margin: 20px 0">
                        <span>派送时间选择：</span>
                        <lar-field-date v-model="dateTimeFour" :action="'search'" style="width: 300px;"></lar-field-date>
                    </div>
                    <div style="margin-bottom: 20px">
                        <span style="margin-right: 10px">状态选择:</span>
                        <el-select v-model="driverStatus"  placeholder="请选择" style="width: 300px;">
                            <el-option
                                    v-for="item in driverList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                    <el-button type="primary"  :disabled="disabledFour" icon="el-icon-download" :loading="disabledFour"  @click="exportDriver">{{disabledFour?'导出中':'导出司机'}}</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "ExportData",
        data() {
            return {
                checkStatus:'',
                loading:false,
                userName:null,
                options:[
                    {
                        value: -11,
                        label: '用户取消'
                    },{
                        value: -12,
                        label: '系统取消'
                    },{
                        value: -20,
                        label: '已退款'
                    },{
                        value: -30,
                        label: '已赔付'
                    },{
                        value: -1,
                        label: '地址异常'
                    },{
                        value: 0,
                        label: '待处理'
                    },{
                        value: 5,
                        label: '已打单'
                    },{
                        value: 10,
                        label: '确认'
                    },{
                        value: 20,
                        label: '已付款'
                    },{
                        value: 30,
                        label: '待取件'
                    },{
                        value: 40,
                        label: '取货中'
                    },{
                        value: 45,
                        label: '取货完成'
                    },{
                        value: 47,
                        label: '待接管/调度'
                    },{
                        value: 50,
                        label: '取货返回中'
                    },{
                        value: 55,
                        label: '取货返回完成'
                    },{
                        value: 60,
                        label: '中转中'
                    },{
                        value: 65,
                        label: '中转已取'
                    },{
                        value: 67,
                        label: '中转接管'
                    },{
                        value: 68,
                        label: '待接管/调度'
                    },{
                        value: 70,
                        label: '中转已送'
                    },{
                        value: 90,
                        label: '派件已取'
                    },{
                        value: 92,
                        label: '派送中'
                    },{
                        value: 94,
                        label: '转交第三方派送'
                    },{
                        value: 96,
                        label: '第三方已取货'
                    },{
                        value: 98,
                        label: '第三方派送已签收'
                    },{
                        value: 100,
                        label: '完成'
                    }
                ],
                userOption:[],
                driverList:[
                    {
                        value: 'sign',
                        label: '签到'
                    },{
                        value: 'notsign',
                        label: '未签到'
                    }
                ],
                orderStatus:[],
                dateTimeOne:[],
                dateTimeTwo:[],
                dateTimeFour:[],
                disabledOne:false,
                disabledTwo:false,
                disabledThree:false,
                disabledFour:false,
                srcReturn: '',
                driverStatus: 'sign'
            }
        },
        mounted() {
            // let nowDate = new Date();
            // let year = nowDate.getFullYear();
            // let mounth = nowDate.getMonth() + 1;
            // if (mounth < 10) {
            //     mounth = '0' + mounth;
            // }
            // let day = nowDate.getDate();
            // this.dateTimeFour = year + '-' + mounth + '-' + day;
            this.getUserList('');
        },
        methods: {
            remoteMethod(query) {
                if (query !== '') {
                    this.loading = true;
                    setTimeout(() => {
                        this.getUserList(query);
                    }, 200);
                } else {
                    this.userOption = [];
                }
            },
            getUserList(val) {
                this.userOption = [{
                    id:'all',
                    phone:'',
                    name:'不选择用户'
                }];
                let query={};
                if (!val) {
                    query={};
                } else {
                    query['name|phone$'] = '%' + val + '%';
                }
                this.$http.get(this.$larfree.httpQuery(query, 'common/user'))
                    .then((response) => {
                        this.loading = false;
                        response.data.data.forEach(item=>{
                            this.userOption.push(item);
                        })
                        // this.userOption.concat(response.data.data);
                    })
                    .catch((error) => {
                        this.loading = false;
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
            exportOrderDetail() {
                if (this.dateTimeOne.length === 0) {
                    this.$message.error('请选择时间');
                    this.disabledOne = false;
                    return;
                }
                if (this.userName == 'all') {
                    this.userName = '';
                }
                let params = {
                    type: this.checkStatus,
                    username: this.userName,
                    status: this.orderStatus,
                    start_time: this.dateTimeOne[0],
                    end_time: this.dateTimeOne[1]
                };
                this.disabledOne = true;
                this.$http.post('express/exportOrderMore',params)
                    .then((response) => {
                        window.location.href = response.data.data[0];
                        this.disabledOne = false;
                    })
                    .catch((error) => {
                        this.disabledOne = false;
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
            exportAreaStatics() {

                if (this.dateTimeTwo.length === 0) {
                    this.$message.error('请选择时间');
                    this.disabledTwo = false;
                    return;
                }
                this.disabledTwo = true;
                this.$http.get('express/orderCounts?start_time=' + this.dateTimeTwo[0] + '&end_time=' + this.dateTimeTwo[1])
                    .then((response) => {
                        window.location.href = response.data.data[0];
                        this.disabledTwo = false;
                    })
                    .catch((error) => {
                        this.disabledTwo = false;
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
            exportOrderStatics() {
                this.disabledThree = true;
                this.$http.get('express/exportCount')
                    .then((response) => {
                        window.location.href = response.data.data[0];
                        this.disabledThree = false;
                    })
                    .catch((error) => {
                        this.disabledThree = false;
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
            exportDriver() {
                if (this.dateTimeFour.length === 0) {
                    this.$message.error('请选择时间');
                    return;
                }
                this.disabledFour = true;
                this.$http.get('express/exportDriverInfo?type=' + this.driverStatus + '&start_time=' + this.dateTimeFour[0] + '&end_time=' + this.dateTimeFour[1])
                    .then((response) => {
                        window.location.href = response.data.data[0];
                        this.disabledFour = false;
                    })
                    .catch((error) => {
                        this.disabledFour = false;
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
        }
    }
</script>

<style scoped lang="less">
.export-data{
    padding: 10px;
    .export-data-title{
        background-color: #fff;
        height: 42px;
        line-height: 42px;
        padding-left: 16px;
        font-size: 16px;
        border-bottom: 2px solid #eee;
    }
    .export-data-contents{
        background-color: #fff;
        padding: 0 0 20px 16px;
        .export-data-contents-title{
            font-size: 20px;
            color: #000;
            padding: 20px 0;
        }
    }
}
</style>
